#ifndef TRAFFIC_JAM_CAR_LOGIC_HPP
#define TRAFFIC_JAM_CAR_LOGIC_HPP

#include "direction.hpp"
#include "pthreadwrapper.hpp"
#include <iostream>

namespace jam {

extern mutex::mutex_quad_t mutex_quad;

template<direction_t dir>
void *car_logic(void *) {
  constexpr direction_t opposite_dir = opposite<dir>::value;
  mutex::lock<mutex_quad, dir>();
  mutex::lock<mutex_quad, opposite_dir>();
  std::cout << std::string("Leaving >> ") + to_string(dir) + " -> " + to_string(opposite_dir);
  mutex::unlock<mutex_quad, dir>();
  mutex::unlock<mutex_quad, opposite_dir>();
  std::cout << " >> Clear" << std::endl;
  return nullptr;
}

}

#endif //TRAFFIC_JAM_CAR_LOGIC_HPP
